package cn.wzy.controller;



import cn.wzy.dto.RegisterDTO;
import cn.wzy.dto.WxBindDTO;
import cn.wzy.pojo.User;
import cn.wzy.results.ResponseResult;
import cn.wzy.service.UserService;
import cn.wzy.vo.GoPageVo;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2023-02-06 16:25:41
 */
@RestController
@RequestMapping("user")
public class UserController{
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;
    
    /*
    * 查询分页
    * */
    @PostMapping("/page")
    public ResponseResult getUserPage(@RequestBody GoPageVo goPageVo){
        return userService.getUserPage(goPageVo);
    }

    /*
    * 查询
    * */
    @GetMapping("/{id}")
    public ResponseResult getUser(@PathVariable("id") Long id){
        return userService.getUser(id);
    }

    /*
    * 新增和修改
    * */
    @PostMapping
    public ResponseResult saveUser(@RequestBody User user){
        return userService.saveUser(user);
    }

    /*
    * 删除
    * */
    @DeleteMapping("/{id}")
    public ResponseResult deleteUser(@PathVariable("id") Long id){
        return userService.deleteUser(id);
    }


    /*
    * 批量删除
    * */
    @PatchMapping
    public ResponseResult deleteUserList(@RequestBody List<Long> ids){
        return userService.deleteUserList(ids);
    }


    /*
    * 注册用户
    * */
    @PostMapping("/register")
    public ResponseResult register(@RequestBody RegisterDTO registerDTO){
        return userService.register(registerDTO);
    }

    /*
    * wx绑定手机号
    * */
    @PostMapping("/bind/wechat")
    public ResponseResult bindWechat(@RequestBody WxBindDTO wxBindDTO){
        return userService.bindWechat(wxBindDTO);
    }

}

